﻿Pages_Game_JackPort = new function () {
    this.variable = new function () {
        this.GameId = -1;
    };
    this.documentReady = function () {
        this.variable.GameId = $("#ddlGame").val();
        this.bindData();
    };
    this.bindData = function () {
        Loading.showProcess();
        $.ajax({
            type: "GET",
            url: "/handler/HandlerConfigGame.ashx",
            data: { t: "GameGetInfo", gameId: this.variable.GameId },
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            cache: false,
            success: function (data) {
                $("#txtJackpotMinBetAu").val(data.JackpotMinBetAu);
                $("#txtJackpotBlockAu").val(data.JackpotBlockAu);
                $("#txtJackpotJumpAu").val(data.JackpotJumpAu);
                $("#txtMaximumJackpotAu").val(data.MaximumJackpotAu);
                $("#txtJackpotStartAu").val(data.JackpotStartAu);
                $("#ddlJackpotStatusAu").val(data.JackpotStatusAu);

                $("#txtJackpotMinBetAg").val(data.JackpotMinBetAg);
                $("#txtJackpotBlockAg").val(data.JackpotBlockAg);
                $("#txtJackpotJumpAg").val(data.JackpotJumpAg);
                $("#txtJackpotStartAg").val(data.JackpotStartAg);
                $("#ddlJackpotStatusAg").val(data.JackpotStatusAg);
                $("#txtMaximumJackpotAg").val(data.MaximumJackpotAg);

                $(".changeEvent").css("border-color", "#CCCCCC");
                Loading.closeProcess();
            }
        });
    };

    $("#btnUpdate").live("click", function () {
        Loading.showProcess();
        var mData = {
            id: Pages_Game_JackPort.variable.GameId,
            jackpotMinBetAu: $("#txtJackpotMinBetAu").val(),
            jackpotBlockAu: $("#txtJackpotBlockAu").val(),
            jackpotJumpAu: $("#txtJackpotJumpAu").val(),
            jackpotStartAu: $("#txtJackpotStartAu").val(),
            jackpotStatusAu: $("#ddlJackpotStatusAu").val(),
            jackpotMinBetAg: $("#txtJackpotMinBetAg").val(),
            jackpotBlockAg: $("#txtJackpotBlockAg").val(),
            jackpotJumpAg: $("#txtJackpotJumpAg").val(),
            jackpotStartAg: $("#txtJackpotStartAg").val(),
            jackpotStatusAg: $("#ddlJackpotStatusAg").val(),
            maximumJackpotAu: $("#txtMaximumJackpotAu").val(),
            maximumJackpotAg: $("#txtMaximumJackpotAg").val()
        };
        if (!(mData.jackpotMinBetAu > 0)) mData.jackpotMinBetAu = 0;
        if (!(mData.jackpotBlockAu > 0)) mData.jackpotBlockAu = 0;
        if (!(mData.jackpotJumpAu > 0)) mData.jackpotJumpAu = 0;
        if (!(mData.jackpotStartAu > 0)) mData.jackpotStartAu = 0;
        if (!(mData.jackpotStatusAu > 0)) mData.jackpotStatusAu = 0;
        if (!(mData.jackpotMinBetAg > 0)) mData.jackpotMinBetAg = 0;
        if (!(mData.jackpotBlockAg > 0)) mData.jackpotBlockAg = 0;
        if (!(mData.jackpotJumpAg > 0)) mData.jackpotJumpAg = 0;
        if (!(mData.jackpotStartAg > 0)) mData.jackpotStartAg = 0;
        if (!(mData.jackpotStatusAg > 0)) mData.jackpotStatusAg = 0;
        if (!(mData.maximumJackpotAu > 0)) mData.maximumJackpotAu = 0;
        if (!(mData.maximumJackpotAg > 0)) mData.maximumJackpotAg = 0;

        $.ajax({
            type: "POST",
            url: "/WebService/WSGame.asmx/JackPortUpdate",
            data: JSON.encode(mData),
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            cache: false,
            success: function (data) {
                if (typeof (data) != "undefined" && data != null) {
                    Loading.closeProcess();
                    if (data.d == -1) {
                        jAlert("Bạn không có quyền thực hiện chức năng này!");
                    }
                    if (data.d > 0) {
                        jAlert("Cập nhật thành công!");
                        Pages_Game_JackPort.documentReady();
                    } else {
                        jAlert("Có lỗi xảy ra trong quá trình xử lý!");
                    }
                }
            }
        });
    });
};